package com.qyhl.webtv.module_broke.utils.radiobutton;

import android.content.Context;
import android.graphics.drawable.AnimationDrawable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.qyhl.webtv.module_broke.R;


/**
 * Created by qyhl on 2017/9/5.
 */

public class ScoopButton extends RelativeLayout {
    private ImageView mAnimaView, mPlayerBtn;
    private TextView mPlayerDuration;

    private View view;

    AnimationDrawable animationDrawable;

    public ScoopButton(Context context) {
        super(context);
        initView(context);
    }

    public ScoopButton(Context context, AttributeSet attrs) {
        super(context, attrs);
        initView(context);
    }

    public ScoopButton(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView(context);
    }

    private void initView(Context context) {
        view = LayoutInflater.from(context).inflate(R.layout.view_scoop_btn, this, true);
        mAnimaView = (ImageView) view.findViewById(R.id.scoop_radio_anima);
        mPlayerBtn = (ImageView) view.findViewById(R.id.radio_player_state);
        mPlayerDuration = (TextView) view.findViewById(R.id.radio_duration);
    }

    //启动动画
    public void startAnimation() {
        mPlayerBtn.setImageResource(R.drawable.radio_player_stop);
        mAnimaView.setImageResource(R.drawable.scoop_voice_start);
        animationDrawable = (AnimationDrawable) mAnimaView.getDrawable();
        animationDrawable.start();
    }

    /**
     * 关闭动画
     */
    public void endAnimation() {
        mPlayerBtn.setImageResource(R.drawable.radio_player_btn);
        mAnimaView.setImageResource(R.drawable.scoop_voice_end);
        animationDrawable = (AnimationDrawable) mAnimaView.getDrawable();
        animationDrawable.start();
    }

    /**
     * 设置初始时间
     * @param content
     */
    public void setContent(String content) {
        mPlayerDuration.setText(content);
    }
}
